package com.sunjy.apollo1.servicesImpl;

import java.util.List;

import com.sunjy.apollo1.mapper.PersonMapper;
import com.sunjy.apollo1.model.Person;
import com.sunjy.apollo1.services.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.sunjy.common.domain.ApiResponseT;

import tk.mybatis.mapper.entity.Example;

@Service
public class PersonServiceImpl implements PersonService {
	@Autowired
	private com.sunjy.apollo1.mapper.PersonMapper PersonMapper;

	public ApiResponseT<Object> insert() {
		Person p=new Person();
		p.setCla("4年级");
		p.setName("sunjy");
		p.setPhone("11111111111");
		PersonMapper.insert(p);
		return ApiResponseT.success();
	}

	@Override
	public ApiResponseT<Object> select() {
		PageHelper.startPage(0, 10);
		List<Person> list=PersonMapper.selectAll();
		System.out.println(JSON.toJSON(list));
		return ApiResponseT.success(list);
	}

	@Override
	public ApiResponseT<Object> selectExample() {
		PageHelper.startPage(1, 10);
		Example example = new Example(Person.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("name", "%" + "uhh" + "%");
		List<Person> list=PersonMapper.selectByExample(example);
		System.out.println(JSON.toJSON(list));
		return ApiResponseT.success(list);
	}

}
